﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Backup.ValueConverter
{
    using System.Collections.ObjectModel;
    using System.Globalization;
    using System.Windows.Data;

    public class List2String : IValueConverter
    {
        #region Implementation of IValueConverter

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            ObservableCollection<string> strings = (ObservableCollection<string>)value;
            return String.Join("; ",strings.ToArray());
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            string val = (string) value;
            var vals = val.Split(';');

            ObservableCollection<string> strings = new ObservableCollection<string>();
            foreach (string s in vals)
            {
                string trimmed = s.Trim();
                if (!string.IsNullOrEmpty(trimmed))
                    strings.Add(trimmed);
            }
            return strings;
        }

        #endregion
    }
}